package project.bluetooth.com.loadsirproject;

import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import project.bluetooth.com.loadsirproject.dialog.EditNameDialogFragment;
import project.bluetooth.com.loadsirproject.dialog.LoginDialogFragment;
import project.bluetooth.com.loadsirproject.dialog.SignInDialogFragment;

public class MainActivity extends AppCompatActivity implements SignInDialogFragment.SignInInputListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

       /* LoadService loadService = LoadSir.getDefault().register(this, new Callback.OnReloadListener() {
            @Override
            public void onReload(View v) {
                //重新加载逻辑

            }
        }, new Convertor<BResponse>() {
            @Override
            public Class<? extends Callback> map(BResponse httpResult) {
                Class<? extends Callback> resultCode = SuccessCallback.class;
                switch (httpResult.getCode()) {
                    case URLContants.SUCCESS_CODE://成功回调
                        if (null == httpResult.getData()) {
                            resultCode = EmptyCallback.class;
                        } else {
                            resultCode = SuccessCallback.class;
                        }
                        break;
                    case URLContants.ERROR_CODE:
                        resultCode = ErrorCallback.class;
                        break;
                }
                return resultCode;
            }
        });*/

        tvDialogListener();
    }

    public void tvDialogListener() {
        Button btn1 = findViewById(R.id.id_btn_1);
        Button btn2 = findViewById(R.id.id_btn_2);
        Button btn3 = findViewById(R.id.id_btn_3);
        Button btn4 = findViewById(R.id.id_btn_4);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog1();
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog2();
            }
        });
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog3();
            }
        });
        btn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog4();
            }
        });
    }

    private void showDialog1() {
        EditNameDialogFragment editNameDialog = new EditNameDialogFragment();
        editNameDialog.show(getSupportFragmentManager(), "EditNameDialog");
    }

    private void showDialog2() {
        LoginDialogFragment loginDialog = new LoginDialogFragment();
        loginDialog.show(getSupportFragmentManager(), "EditNameDialog");
    }

    private void showDialog3() {
        SignInDialogFragment signDialog = new SignInDialogFragment();
        signDialog.show(getSupportFragmentManager(), "EditNameDialog");
    }

    private void showDialog4() {
        EditNameDialogFragment newFragment = new EditNameDialogFragment();

        boolean mIsLargeLayout = getResources().getBoolean(R.bool.large_layout);
        Log.e("TAG", mIsLargeLayout + "");
        if (mIsLargeLayout) {
            // The device is using a large layout, so show the fragment as a
            // dialog
            newFragment.show(getSupportFragmentManager(), "dialog");
        } else {
            // The device is smaller, so show the fragment fullscreen
            android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            // For a little polish, specify a transition animation
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            // To make it fullscreen, use the 'content' root view as the
            // container for the fragment, which is always the root view for the activity
            transaction.replace(R.id.id_ly, newFragment).commit();
        }
    }

    @Override
    public void onLoginInputComplete(String username, String password) {
        Toast.makeText(this, "帐号：" + username + ",  密码 :" + password,
                Toast.LENGTH_SHORT).show();
    }

}
